let obj = { name: {name: 'hahah'}, age: 18 };

// 观察数据
function observer(obj) {
	if (typeof obj != "object") {
		return obj;
	}
	for (let key in obj) {
		defineReactive(obj, key, obj[key]);
	}
}

// 把对象中的所有属性都采用 Object.defineProperty 方式定义
function defineReactive(obj, key, value) {
	observer(value)
	Object.defineProperty(obj, key, {
		get() {
			console.log("获取数据了");
			return value;
		},
		set(val) {
			if (value != val) {
				console.log("数据更新了");
				value = val;
			}
		},
	});
}
observer(obj);

obj.name.name = 'zhangsan'
// console.log(obj.name);

